<?php

class Sgit_View_Breadcrumbs
{
        private $path = array();
 
        function __construct()
        {
            $this->addStep('Home', '/');
        }
        
        
        public function reset()
        {
            unset($this->path);
            return $this;
        }

        
        public function addStep($title, $link = '')
        {
            $item = array('title' => $title);
            if (strlen($link) > 0)
                $item['link'] = $link;
            $this->path[] = $item;
            
            $this->_show();
            
            return $this;
        }
        
        
        
        public function getPath()
        {
            return $this->path;
        }
        
        
        private function _show()
        {
            	       
            $view= Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('view');
      

	        if (isset($this->path) && is_array($this->path))
	            $trail = $this->path;
	        else
	            $trail = array();

	 
	        $separator = ' &gt; ';
	 

	        $links = array();
	 
	        $trailSize = count($trail);
	        
	        for ($i = 0; $i < $trailSize; $i++) {
				
	            $title = $view->escape($trail[$i]['title']);
	 			
	            if (isset($trail[$i]['link']) && $i < $trailSize - 1)
	                $links[] = '<a href="' . $trail[$i]['link'] . '">' . $title . '</a>';
	            else
	                $links[] = $title;
	        }
	 
	        $breadcrumbs= implode($separator . "\n", $links);
	        
	       
        	$view->breadcrumbs = $breadcrumbs;
	        
	        return true;
	    }
    

        
}